package com.dylan.历史.多线程.线程池;

import com.dylan.历史.util.LogUtil;
import com.dylan.历史.util.SleepUtils;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @Auther: ankang
 * @Date: 2019/3/8 14:20
 * @Description:
 */
public class 定时线程池 {

    static ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);

    public static void main(String[] args) {
        // 当任务结束后，延迟指定时间再执行任务
        scheduledExecutorService.scheduleWithFixedDelay(() -> {
            SleepUtils.seconds(1);
            LogUtil.info("执行定时任务1");
        }, 0, 5, TimeUnit.SECONDS);
    }
}
